package com.cssw.fyzb.tps.api.pay;

import com.alibaba.fastjson.JSON;
import com.cssw.fyzb.tps.service.pay.AliPayService;
import com.ydn.appserver.Action;
import com.ydn.appserver.Request;
import com.ydn.appserver.Response;
import com.ydn.appserver.annotations.Function;
import com.ydn.appserver.annotations.Parameter;
import com.ydn.appserver.annotations.Type;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.Map;

/**
 * @Author: chenchao
 * @Date: 2020/8/31 10:57
 */

@Function(description = "支付宝异步通知校验", parameters = {
        @Parameter(name = "params", type = Type.String, description = "参数", required = true),
})
@Component
public class AliVerifyNotify implements Action {

    @Autowired
    private AliPayService aliPayService;

    @Override
    public Response execute(Request request) throws Exception {
        String params = request.getString("params");
        Map param = JSON.parseObject(params, Map.class);
        if (aliPayService.certNotifyUrl(param)) {
            return Response.success();
        }
        return Response.fail("校验失败");
    }
}
